const getMonthFormat = function (now) {
    let year = now.getFullYear(); //年
    let month = now.getMonth() + 1; //月
    let clock = year + "-";
    if (month < 10) {
        clock += "0";
    }
    clock += month;
    return clock
}

//获取年月日
const getDateFormat = function (now) {
    let year = now.getFullYear(); //年
    let month = now.getMonth() + 1; //月
    let day = now.getDate(); //日
    let hh = now.getHours(); //时
    let mm = now.getMinutes(); //分
    let ss = now.getSeconds(); //秒
    let clock = year + "-";
    if (month < 10) {
        clock += "0";
    }
    clock += month + "-";
    if (day < 10) {
        clock += "0";
    }
    return clock
}
//时间格式化时分秒
const getTimeFormat = function (now) {
    var hh = now.getHours(); //时
    var mm = now.getMinutes(); //分
    var ss = now.getSeconds(); //秒
    var clock = "";
    if (hh < 10) {
        clock += "0";
    }
    clock += hh + ":";
    if (mm < 10) {
        clock += "0";
    }
    clock += mm + ":";
    if (ss < 10) {
        clock += "0";
    }
    clock += ss;
    return clock;
}
//时间格式化将new Date()对象转换为00:00:00格式
const getAllTimeFormat = function (now, split) {
    let year = now.getFullYear(); //年
    let month = now.getMonth() + 1; //月
    let day = now.getDate(); //日
    let hh = now.getHours(); //时
    let mm = now.getMinutes(); //分
    let ss = now.getSeconds(); //秒
    let clock = ''
    if (split) {
        clock = year + split;
        if (month < 10) {
            clock += "0";
        }
        clock += month + split;
        if (day < 10) {
            clock += "0";
        }
    } else {
        clock = year + '-';
        if (month < 10) {
            clock += "0";
        }
        clock += month + '-';
        if (day < 10) {
            clock += "0";
        }
    }
    clock += day + " ";
    if (hh < 10) {
        clock += "0";
    }
    clock += hh + ":";
    if (mm < 10) {
        clock += "0";
    }
    clock += mm + ":";
    if (ss < 10) {
        clock += "0";
    }
    clock += ss;
    return clock;
}

//2个date天 day1='2014-03-31 00:00:01';  day2=2014-03-31 00:00:01这种格式
function getDay(day1, day2) {
    var s = day1;
    var dt = Date.parse(s.replace(/-/g, "/"));
    var day1 = new Date(dt);

    var s = day2;
    var dt = Date.parse(s.replace(/-/g, "/"));
    var day2 = new Date(dt);

    var date3 = day1.getTime() - day2.getTime()  //时间差的毫秒数
    //计算出相差天数
    return Math.floor(date3 / (24 * 3600 * 1000))
}
export {
    getMonthFormat,
    getDateFormat,
    getTimeFormat,
    getAllTimeFormat,
    getDay
}